<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/common/header.jsp"%> 
 
<div style="margin:20px 0;"></div>
<div class="easyui-panel" >
	<div style="padding:10px 60px 20px 60px">
    <form id="hostlargeForm"  name="hostlargeForm" method="post" >
    	<input type="hidden" id="host_large_uuid" name="host_large_uuid" value="${hostLarge.host_large_uuid}"/>
    	<input type="hidden" id="ins_uuid" name="ins_uuid" value="${hostLarge.ins_uuid}"/>
    	<input type="hidden" id="service_uuid" name="service_uuid" value="${hostLarge.service_uuid}"/>
    	<input type="hidden" id="service_param_uuid" name="service_param_uuid" value="${hostLarge.service_param_uuid}"/>
    	<input type="hidden" id="area_cd" name="area_cd" value="${hostLarge.area_cd}"/>
    	<input type="hidden" id="channel_no" name="channel_no" value="${channel_no}"/>
    	<table cellpadding="5" style="width:100%">
    		<tr>
    			<td>渠道方商户号:</td>
    			<td><input class="easyui-textbox" type="text" id="trf_mchnt_cd" name="trf_mchnt_cd" data-options="required:true,validType:['trfmchntcd']" value="${hostLarge.trf_mchnt_cd }"></input></td>  
    			<td>渠道方终端号:</td>
    			<td><input class="easyui-textbox" type="text" id="trf_term_id" name="trf_term_id" data-options="validType:['trftermid']" value="${hostLarge.trf_term_id }"></input></td>   	     			
    		</tr>
    		<tr>
    			<td>商户名称:</td>
    			<td><input class="easyui-textbox" type="text" id="term_nm" name="term_nm" data-options="required:true,validType:['length[0,20]']" value="${hostLarge.term_nm }"></input></td>    
    			<td>所属机构:</td>
    			<td><input class="easyui-textbox" type="text" id="insname" name="insname" readonly="readonly" data-options="required:true" value="${hostLarge.insname }"></input>
    			<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-search" id="selelctinsname">选择</a></td> 	     			
    		</tr>
    		<tr>
    			<td>业务名称:</td>
    			<td><input class="easyui-textbox" type="text" id="sername" name="sername" readonly="readonly" data-options="required:true" value="${hostLarge.sername }"></input></td>
    			<td>业务参数名称:</td>
    			<td><input class="easyui-textbox" type="text" id="purname" name="purname" readonly="readonly" data-options="required:true" value="${hostLarge.purname }"></input>
    			<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-search" id="selelctsername">选择</a></td>     	     			
    		</tr>
    		<tr>
    			<td>所属地区:</td>
    			<td><input class="easyui-textbox" type="text" id="areaname" name="areaname" readonly="readonly"  value="${hostLarge.areaname }"></input>
    			<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-search" id="selelctarea">选择</a>
    			<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-clear" id="cleararea">清除</a></td> 
    			<td>收单行号:</td>
    			<td><input class="easyui-textbox" type="text" id="acq_ins_cd" name="acq_ins_cd" data-options="required:true,validType:['acqinscd']" value="${hostLarge.acq_ins_cd }"></input></td>    	     			
    		</tr>
    		<tr>
    			<td>主秘钥索引:</td>
    			<td><input class="easyui-textbox" type="text" id="master_key_idx" name="master_key_idx" data-options="validType:['masterkeyidx']" value="${hostLarge.master_key_idx }"></input></td> 
    			<td>主秘钥:</td>
    			<td><input class="easyui-textbox" type="text" id="master_key" name="master_key" data-options="validType:['masterkey']" value="${hostLarge.master_key }"></input></td>    	     			
    		</tr>  
    		<tr>
    			<td>所属通道:</td>
    			<td><input class="easyui-textbox" type="text" id="chnname" name="chnname" readonly="readonly" data-options="" value="${chnname }"></input></td>    
    			<td>借记卡-最小手续费(元):</td>
    			<td><input class="easyui-textbox" type="text" id="debit_minfee" name="debit_minfee" data-options="required:true,validType:['checkfee']" value="${hostLarge.debit_minfee }"></input></td> 	     			
    		</tr>
    		<tr>
    			<td>借记卡-扣率(‱):</td>
    			<td><input class="easyui-textbox" type="text" id="debit_rate" name="debit_rate" data-options="required:true,validType:['checkrate']" value="${hostLarge.debit_rate }"></input></td>
    			<td>借记卡-最大手续费(元):</td>
    			<td><input class="easyui-textbox" type="text" id="debit_maxfee" name="debit_maxfee" data-options="required:true,validType:['checkfee']" value="${hostLarge.debit_maxfee }"></input></td>     	     			
    		</tr>
    		<tr>
    			<td>贷记卡-最小手续费(元):</td>
    			<td><input class="easyui-textbox" type="text" id="credit_minfee" name="credit_minfee" data-options="required:true,validType:['checkfee']" value="${hostLarge.credit_minfee }"></input></td> 
    			<td>贷记卡-扣率(‱):</td>
    			<td><input class="easyui-textbox" type="text" id="credit_rate" name="credit_rate" data-options="required:true,validType:['checkrate']" value="${hostLarge.credit_rate }"></input></td>    	     			
    		</tr>
    		<tr>
    			<td>贷记卡-最大手续费(元):</td>
    			<td><input class="easyui-textbox" type="text" id="credit_maxfee" name="credit_maxfee" data-options="required:true,validType:['checkfee']" value="${hostLarge.credit_maxfee }"></input></td> 
    			<td>签到标志:</td>
    			<td><code:codeSelect id="sign_st" name="sign_st" code_type="sign_st" showSelect="false" selectId="${hostLarge.sign_st}"></code:codeSelect></td>    	     			
    		</tr>   		 		  		    		 
    	</table>
    
	    <div style="text-align:center;padding:5px">
	    	<a href="javascript:void(0)" class="easyui-linkbutton btn" iconCls="icon-save" id="saveBtn">保存</a>
	    	<a href="javascript:void(0)" class="easyui-linkbutton btn" iconCls="icon-back" onclick="back()">返回</a>
	    </div>
    </form>
    </div>
</div>
<div id="commonTree">
	<div id="ztreeObj" class="ztree"></div>
</div>
<script>
$(document).ready(function() {
	$.extend($.fn.textbox.defaults.rules, {
		trfmchntcd: {     
            validator: function(value){               
                 var reg = new RegExp("^[a-zA-Z0-9_]{0,50}$"); 
                 return reg.test(value);  
            },     
            message: '只能包含数字字母和“_”，长度0-50'     
        },        
        trftermid: {     
            validator: function(value){               
                 var reg = new RegExp("^[a-zA-Z0-9_]{0,15}$"); 
                 return reg.test(value);  
            },     
            message: '只能包含数字字母和“_”，长度0-15'     
        },
		acqinscd: {     
            validator: function(value){               
                 var reg = new RegExp("^[a-zA-Z0-9_]{0,11}$"); 
                 return reg.test(value);  
            },     
            message: '只能包含数字字母和“_”，长度0-11'     
        },
        masterkeyidx: {     
            validator: function(value){               
                 var reg = new RegExp("^[0-9]{0,6}$"); 
                 return reg.test(value);  
            },     
            message: '只能包含数字，长度0-6'     
        },
        masterkey: {     
            validator: function(value){               
                 var reg = new RegExp("^[\x01-\x7f]{0,1000}$"); 
                 return reg.test(value);  
            },     
            message: '不能输入中文'     
        },
        checkfee: {     
            validator: function(value){                                
                 return /^(?=([0-9]{1,8}$|[0-9]{1,8}\.))(0|[1-9][0-9]*)(\.[0-9]{1,2})?$/.test(value);  
            },     
            message: '格式不符或长度超限'     
        },  
        checkrate: {     
            validator: function(value){                                
                 return /^(?=([0-9]{1,6}$|[0-9]{1,6}\.))(0|[1-9][0-9]*)(\.[0-9]{1,2})?$/.test(value);  
            },     
            message: '格式不符或长度超限'     
        }
	});
	var commonTree;	
	var setting = {
			callback:{
				onClick: zTreeOnClick
			},
			data:{				
				simpleData:{enable: true}
			}
		}
	function zTreeOnClick(event, treeId, treeNode) {
		if(treeNode.flag!="p"){
			$.jpmessage.info('只能选择业务参数!');
			return;
		}	    
	};
	/*选择机构*/
	$("#selelctinsname").click(function(){
		commonTree = showInsTree(insselected, null,null);				
	})
	
	/*选择业务参数*/
	$("#selelctsername").click(function(){
		openTree("../serviceInf/getServiceInfTree.do","选择业务参数",serselected,setting);		
	})
	
	/*选择地区*/
	$("#selelctarea").click(function(){
		showAreaTree(areaselected);				
	});
	
	/*清除地区*/
	$("#cleararea").click(function(){
		$("#area_cd").val("");
		$("#areaname").textbox("setValue", "");
	})
	
	function insselected(){
		var nodes = commonTree.getSelectedNodes();
		if(nodes && nodes.length > 0){
			$("#ins_uuid").val(nodes[0].ID);
			$("#insname").textbox("setValue", nodes[0].NAME);		
		}
	}
	function areaselected(nodes){		
		if(nodes && nodes.length > 0){
			$("#area_cd").val(nodes[0].ID);
			$("#areaname").textbox("setValue", nodes[0].NAME);		
		}
	}
	function serselected(){
		var nodes = commonTree.getSelectedNodes();
		if(nodes && nodes.length > 0){			
			$("#service_uuid").val(nodes[0].getParentNode().id);
			$("#service_param_uuid").val(nodes[0].id);
			$("#purname").textbox("setValue", nodes[0].name);		
			$("#sername").textbox("setValue", nodes[0].getParentNode().name);
		}
	}
	
	function openTree(url,title,callback,setting){
		$.ajax({
			url: url,
			async: false,
			success: function(result){
				commonTree=$.fn.zTree.init($("#ztreeObj"), setting, result);
				commonTree.expandNode(commonTree.getNodesByFilter(function (node) { return node.level == 0 }, true), true, false, true);
			}
		});
		openModal("#commonTree", {width:400, height:400,title:title}, callback);
	}
	
	$("#saveBtn").click(function(){	
		if($("#hostlargeForm").form("validate")){	
			if($("#debit_minfee").val() != null && $("#debit_minfee").val() != "" && $("#debit_minfee").val() != 0.00
	            && $("#debit_maxfee").val()!=null && $("#debit_maxfee").val()!="" && $("#debit_maxfee").val() != 0.00
	            && parseFloat($("#debit_minfee").val()) > parseFloat($("#debit_maxfee").val())){
	            $.jpmessage.info('借记卡-最小手续费不应大于借记卡-最大手续费');
	            return;
	        }
			if($("#credit_minfee").val() != null && $("#credit_minfee").val() != "" && $("#credit_minfee").val() != 0.00
	            && $("#credit_maxfee").val()!=null && $("#credit_maxfee").val()!="" && $("#credit_maxfee").val() != 0.00
	            && parseFloat($("#credit_minfee").val()) > parseFloat($("#credit_maxfee").val())){
	            $.jpmessage.info('贷记卡-最小手续费不应大于贷记卡-最大手续费');
	            return;
	        }
			var options ={   
		            url:'<c:url value="/hostlarge/checkHostLarge.do"/>',   
		            type:'post',                    
		            success:function(data){		            	  
						  if("success"==data){					  
							  //表单提交的方法、比如ajax提交
					    	  $("#hostlargeForm").attr("action","../hostlarge/saveHostLarge.do?");
					    	  document.getElementById("hostlargeForm").submit();  						  
						  }else{
							  $.jpmessage.info('渠道方商户号不能重复!');
						  }
		            }   
		         };
			$("#hostlargeForm").ajaxSubmit(options); 
		}
		
	});
	$("body").keydown(function() {
        if (event.keyCode == "13") {//keyCode=13是回车键
            $('#saveBtn').click();
        }
    });
	
})
</script>